package p532.p1.implementations;

import acm.graphics.GObject;
import acm.graphics.GOval;
import acm.graphics.GPoint;
import java.awt.Color;
import java.awt.Point;

import p532.p1.interfaces.abGameBoard;
import p532.p1.interfaces.iGameObject;

/**
 *
 * @author han
 */
public class Ball extends GOval implements iGameObject {

    public Ball(double x, double y, double width, double height, Color color) {
        super(x, y, width, height);

        this.setColor(color);
        this.setFillColor(color);
        this.setFilled(true);
        
    }

    @Override
    public int getObjectType() {
        return GAME_OBJECT_TYPE_BALL;
    }

    @Override
    public Boolean moveToNextStepOfPath(int Width, int Height, double LocX, double LocY) {
        // TODO
        //move(0, 2);
    	//this.move(LocX,LocY);
        GPoint ballLoc = this.getLocation();
        if (ballLoc.getX() > Width) LocX = -LocX;
		if (ballLoc.getX() <= 0) LocX = -LocX;
		if (ballLoc.getY() <= 0) LocY = -LocY;
		if (ballLoc.getY() > Height) return true; 
		this.move(LocX,LocY);
		return false;
    }

    public GObject getCollidingGameObject(abGameBoard gameBoard) {
        // TODO 
    	GObject collObj;
    	if (!this.isVisible()) return null;
		GPoint ballLoc = this.getLocation();		
		Point arrPoints[] = new Point[4];
		arrPoints[0]= new Point(0,0);
		arrPoints[1]= new Point(0,10);
		arrPoints[2]= new Point(10,10);
		arrPoints[3]= new Point(10,0);
		for (int i =0; i< 4; i++)
		{
			collObj = gameBoard.getElementAt(ballLoc.getX()+arrPoints[i].x, ballLoc.getY()+arrPoints[i].y);
			if (collObj != null)
					return collObj;
		}
		
        return null;
    }
}
